
<template>
    <el-dialog class="eldialog" :title="title" :visible.sync="open" width="65%" append-to-body
        :before-close="closeDelfindDialog">
        <div>
            <el-form ref="queryForm" :model="queryParams"  :inline="true" v-show="showSearch">
                <el-form-item label="任务名称">
                    <el-input v-model="info.JIANDINGRENWUNAME" placeholder="请输入任务名称" disabled=""></el-input>
                </el-form-item>
                <el-form-item :label="rowInfo.isRyType==0||rowInfo.isRyType==1?'指定初审人员':'指定复审人员'" required>
                    <el-select v-model="queryParams.userid" placeholder="请选择" @change="selectChange" :disabled="isDataLoaded">
                        <el-option v-for="item in userTreeList" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
        </div>

        <el-divider></el-divider>
        <el-row>
            <el-col :span="24">
                <el-form :model="numInfo" :inline="true">
                    <el-form-item label="任务总数">
                        <el-input v-model="numInfo.ALLNUM" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="当前人分配数">
                        <el-input v-model="numInfo.NOWPERSON" disabled></el-input>
                    </el-form-item>
                </el-form>
            </el-col>

        </el-row>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5" v-if="rowInfo.isRyType == '0'||rowInfo.isRyType == '2'">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskButTap(0)">批量标记分配</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskButTap(1)" :disabled="isDisabled">提交分配</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-minus"  @click="onTaskButTap(2)">取消</el-button>
            </el-col>
        </el-row>

        <tableList :tableHeaderList="tableHeaderList" :tableData="tableData" :loading="loading" :tableHeight="tableHeight"
            @sortChange="sortChange" :isOpenFinds="isOpenFinds" :isRyType="rowInfo.isRyType" @changeCheckBoxTap="changeCheckBoxTap"
            @handleSelectionChange="handleSelectionChange" :isSelection="isSelection"></tableList>
        <pagination v-show="total > 0" :total="total" :page.sync="pageNum" :limit.sync="pageSize"
            @pagination="sdfplistPOST" />
    </el-dialog>
</template>
<script>

import { getshowfield } from "@/api/archive/fileCollection/offlinReception"
import { getjobinfo, getchushennum, getfushengnum,sdfplist, markfp, commitsdfp, cspjfplist, getuserbyrenwuid, pjfprw } from "@/api/archive/archivalAppraisal/bgqx/openArchivesAppraisal"
import tableList from "@/components/tableList/index.vue"
import { getLastIndexOf } from "@/utils/index.js"
export default {
    components: { tableList },
    props: ["open", "rowInfo"],
    watch: {
        rowInfo: {
            handler(valNew) {
                if (valNew) {

                    //0: 初审手动分配,1:初审平均分配,2:复审手动分配,3:复审平均分配,4:重新初审分配,5:重新复审分配,6:人员调整
                    this.queryParams.renwuid = valNew.ID;
                    if (valNew.isRyType == "0") {
                        this.title = "初审手动分配"
                        this.queryParams.type = "chushen"
                    }
                    if (valNew.isRyType == "1") {
                        this.title = "初审自动分配"
                        this.isSelection = false;  //去掉列表复选框
                        this.isOpenFinds = false; //去掉列表标记分配复选框
                        this.queryParams.type = "chushen"

                    }
                    if (valNew.isRyType == "2") {
                        this.title = "复审手动分配"
                        this.queryParams.type = "fushen"
                    }
                    if (valNew.isRyType == "3") {
                        this.title = "复审自动分配"
                        this.isSelection = false;  //去掉列表复选框
                        this.isOpenFinds = false; //去掉列表标记分配复选框
                        this.queryParams.type = "fushen"

                    }
                    getjobinfo(this.rowInfo.ID).then(res => {
                        this.info = res.data.jobinfo;
                        this.getuserPOST();
                    })
                }
            }, immediate: true
        },
    },
    data() {
        return {
            isDisabled:false,
            title: "",//标题
            isSelection: true,//table复选框是否显示,
            isOpenFinds: true, //table 标记分配是否显示
            loading: false,
            // 显示搜索条件
            showSearch: true,
            info: "",//任务信息
            numInfo: {}, //获取任务总数
            userTreeList: [],//人员下拉列表
            pageNum: 1,
            pageSize: 10,
            total: 0,
            fields: [],//组装的表头table需要的参数
            tableHeaderList: [],
            tableData: [],
            tableHeight: "400",
            order: undefined,
            ids: [],
            single: true,
            multiple: true,
            queryParams: {
                userid: undefined,
                type: undefined,
            },
            isDataLoaded: true
        }
    },
    created() {

    },
    methods: {

        //0: 初审手动分配,1:初审平均分配 2:复审手动分配,3:复审平均分配人员下拉列表
        getuserPOST() {
            console.log(this.rowInfo, "+++")
            getuserbyrenwuid({ type: this.queryParams.type, id: this.rowInfo.ID }).then(res => {
                var USERID = res.data.USERID.split(",");
                var USERNAME = res.data.USERNAME.split(",");
                var list = [];
                for (var i in USERID) {
                    list.push({
                        value: USERID[i],
                        label: USERNAME[i]
                    })
                }
                this.userTreeList = list

                if (this.rowInfo.isRyType == 1||this.rowInfo.isRyType == 3) {  //初审平均分配
                    this.queryParams.userid = list[0].value
                }
                this.getshowfieldPost();

                this.getnumPOST();

            })
        },


        //valNew.isRyType="0": 初审手动分配 ,初审平均分配  2:复审手动分配,3:复审平均分配  获取任务总数/当前人分配数/待审核数/占比
        getnumPOST() {
            if (this.queryParams.userid != undefined) {
                if(this.rowInfo.isRyType==0||this.rowInfo.isRyType==1){ // 初审手动分配 ,初审平均分配
                getchushennum(this.info.ID, this.queryParams.userid).then(res => {
                    this.numInfo = res.data;
                })
            }else{ // 2:复审手动分配,3:复审平均分配
                getfushengnum(this.info.ID, this.queryParams.userid).then(res => {
                    this.numInfo = res.data;
                })

            }
            }
        },
        // 获取表头列表
        getshowfieldPost() {
            var level = "";
            if (getLastIndexOf(this.info.SUB_TABLE_NAME) == "F") {  //F 件
                level = "jian"
            } else if (getLastIndexOf(this.info.SUB_TABLE_NAME) == "V") { //卷
                level = "juan"
            } else { //项目
                // level = "xiangmu"
                level = "juan"
            }
            this.loading = true;
            this.fields = [];
            getshowfield({
                categoryId: this.info.categoryId,
                level: level,
                menuId: this.$route.meta.menuId
            }).then(res => {
                this.tableHeaderList = res.data;
                for (var i in res.data) {
                    this.fields.push(res.data[i].FIELD_NAME)
                }
                this.loading = false;

                if (this.rowInfo.isRyType == "0"||this.rowInfo.isRyType == "2") {
                    this.sdfplistPOST()
                } else if (this.rowInfo.isRyType == "1"||this.rowInfo.isRyType == "3") {
                    this.cspjfplistPOST();
                }
            })
        },

        //valNew.isRyType="0": 初审手动分配 获取任务单内的档案数据列表
        sdfplistPOST() {
            sdfplist({
                type: this.queryParams.type,
                order: this.order,
                renwuid: this.info.ID,
                fields: this.fields.toString(),
                menuId: this.$route.meta.menuId,
                pageNum: this.pageNum,
                pageSize: this.pageSize,
                searchcolumn: this.searchcolumn,
                userid: this.queryParams.userid
            }).then(res => {
                for (var i in res.rows) {
                    if (res.rows[i].CHUSHENMARK == 1) {
                        res.rows[i].CHUSHENMARK = true
                    } else {
                        res.rows[i].CHUSHENMARK = false
                    }

                    if (res.rows[i].FUSHENMARK == 1) {
                        res.rows[i].FUSHENMARK = true
                    } else {
                        res.rows[i].FUSHENMARK = false
                    }
                }
                this.tableData = res.rows;
                this.total = res.total;
                this.isDisabled = false // 提交
                this.isDataLoaded = false // 指定初审人员
            })
        },


        // 1:初审平均分配, 获取任务单内的档案数据列表
        cspjfplistPOST() {
            cspjfplist({
                type: this.queryParams.type,
                order: this.order,
                renwuid: this.info.ID,
                fields: this.fields.toString(),
                menuId: this.$route.meta.menuId,
                pageNum: this.pageNum,
                pageSize: this.pageSize,
                searchcolumn: this.searchcolumn,
                userid: this.queryParams.userid
            }).then(res => {
                for (var i in res.rows) {
                    if (res.rows[i].CHUSHENMARK == 1) {
                        res.rows[i].CHUSHENMARK = true
                    } else {
                        res.rows[i].CHUSHENMARK = false
                    }
                    if (res.rows[i].FUSHENMARK == 1) {
                        res.rows[i].FUSHENMARK = true
                    } else {
                        res.rows[i].FUSHENMARK = false
                    }
                }
                this.tableData = res.rows;
                this.total = res.total;
                this.isDisabled = false // 提交
                this.isDataLoaded = false // 指定初审人员
            })
        },
        //关闭
        closeDelfindDialog() {
            this.$emit("closeDelfindDialog")
        },
        //搜索
        handleFindQuery() {

        },

        //下拉事件  //0: 初审手动分配,1:初审平均分配 2:复审手动分配,3:复审平均分配人员下拉列表
        selectChange() {
            if(this.rowInfo.isRyType=='0'||this.rowInfo.isRyType=='2') {//初审手动分配
            this.getnumPOST();
            }
            if(this.rowInfo.isRyType=='1'||this.rowInfo.isRyType=='3'){ //初审自动分配
                this.getnumPOST();
                this.cspjfplistPOST();
            }
        },

        //排序
        sortChange() {
            this.order = val;
            this.getshowfieldPost();
        },
        //多选框选中数据
        handleSelectionChange(ids, single, multiple, selection) {
            console.log(ids, single, multiple, selection)
            this.queryParams.ids = ids;
            this.queryParams.checked = !multiple;
            this.single = single;
            this.multiple = multiple;
        },
        //标记分配复选框
        changeCheckBoxTap(value, row) {
            this.queryParams.checked = value;
            this.queryParams.ids = [row.ID];
            this.markfpPOST()

        },

        //标记分配
        markfpPOST() {
            markfp(this.queryParams).then(res => {
                this.sdfplistPOST();
            })
        },



        //初审手动分配
        onTaskButTap(val) {
            if (val == "2") {
                //取消分配
                sessionStorage.removeItem("listKFJD");
                this.closeDelfindDialog();

            } else if (val == "0") {
                //批量标记分配
                if (this.multiple) {
                    this.$message({ message: '请选择要标记分配的数据哦', type: 'warning' })
                    return false
                } else {
                    this.markfpPOST()

                }
            } else {
                if (this.rowInfo.isRyType == 0||this.rowInfo.isRyType == 2) {  //提交手动分配

                    if (this.multiple) {
                        this.$message({ message: '请选择要分配的数据哦', type: 'warning' })
                        return false
                    }

                    if (this.queryParams.userid == undefined) {
                      if (this.queryParams.type == 'chushen') {
                        this.$message({ message: '请选择初审组人员', type: 'warning' })
                        return false
                      } else {
                        this.$message({ message: '请选择复审组人员', type: 'warning' })
                        return false
                      }
                    }
                    this.isDisabled=true
                    commitsdfp({
                        renwuid: this.queryParams.renwuid,
                        daids: this.queryParams.ids,
                        type: this.queryParams.type,
                        userid: this.queryParams.userid
                    }).then(res => {
                        if (res.code == "200") {
                            this.$modal.msgSuccess("提交成功");
                            this.markfpPOST();
                            this.getnumPOST();
                        }
                    })
                }else{ //提交平均分配任务
                    this.isDisabled=true
                    pjfprw({
                        type:this.queryParams.type,
                        renwuid:this.queryParams.renwuid,
                    }).then(res=>{
                        if (res.code == "200") {
                            this.$modal.msgSuccess("提交成功");
                            this.getnumPOST();
                            this.getshowfieldPost();
                        }
                    })
                }



            }
        }
    }
}
</script>

<style lang="scss" scoped="scoped" >
.eldialog ::v-deep .el-dialog__body {
    padding: 10px 20px 25px !important;
}

.eldialog ::v-deep .el-dialog {
    // padding: 0 20px 20px 20px !important;
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 30px);
    max-width: calc(100% - 30px);
}

.eldialog ::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow-x: hidden;
}

.eldialog ::v-deep ::v-deep .el-form-item__content {
    line-height: 26px;
}

.el-divider {
    margin-top: 0;
}

.eldialog .elinput {
    border: 0 !important
}
</style>
>>>>>>> .r13512
